﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Alfa.Math {
	public class Point : IEquatable<Point> {
		private readonly int dimention;
		private float[] values;
		public Point(int dimention) {
			this.dimention = dimention;
			this.values = new float[dimention];
		}
		public Point(params float[] values)
			: this(values.Length) {
			this.values = values;
		}

		public int Dimention { get { return this.dimention; } }
		public float[] Values { get { return this.values; } }

		public static Vector operator -(Point a, Point b) {
			if (a.Dimention != b.Dimention)
				throw new Exception("Points do not have the same dimentions.");
			else {
				float[] vectorValues = new float[a.Dimention];
				a.Values.CopyTo(vectorValues, 0);
				for (int i = 0; i < a.Dimention; i++) {
					vectorValues[i] += b.Values[i];
				}
				return new Vector(vectorValues);
			}
		}

		public static Vector operator -(Point a, Vector b) {
			if (a.Dimention != b.Dimention)
				throw new Exception("Points do not have the same dimentions.");
			else {
				float[] vectorValues = new float[a.Dimention];
				a.Values.CopyTo(vectorValues, 0);
				for (int i = 0; i < a.Dimention; i++) {
					vectorValues[i] += b.Values[i];
				}
				return new Vector(vectorValues);
			}
		}

		public static Vector operator +(Point a, Vector b) {
			if (a.Dimention != b.Dimention)
				throw new Exception("Points do not have the same dimentions.");
			else {
				float[] vectorValues = new float[a.Dimention];
				a.Values.CopyTo(vectorValues, 0);
				for (int i = 0; i < a.Dimention; i++) {
					vectorValues[i] += b.Values[i];
				}
				return new Vector(vectorValues);
			}
		}

		public bool Equals(Point other) {
			return this.dimention == other.dimention && this.values.SequenceEqual(other.values);
		}
	}
}
